package org.rslai.tcedit.web.service.impl;

import java.io.IOException;

import javax.activation.DataHandler;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.ws.soap.MTOM;

import org.rslai.tcedit.business.TestScriptService;
import org.rslai.tcedit.web.service.CallResult;
import org.rslai.tcedit.web.service.RunConf;
import org.rslai.tcedit.web.service.StatusInfo;
import org.rslai.tcedit.web.service.TCagentWebService;
import org.rslai.tcedit.web.service.TestCaseInfo;
import org.rslai.tcedit.web.service.TestScriptInfo;

/**
 * TCagentWebService的实现类
 * 
 * @author rslai
 * 
 * @spring.bean id="tcAgentWebServiceImpl"
 */
@WebService(endpointInterface = "org.rslai.tcedit.web.service.TCagentWebService", serviceName = "TcAgentWebService")
@MTOM
public class TCagentWebServiceImpl implements TCagentWebService {
	protected TestScriptService testScriptService;

	/**
	 * 注入 testScriptService 对象。所有的测试脚本操作被封装在这个接口中。
	 * @spring.property ref="testScriptService"
	 */
	public final void setTestScriptService(TestScriptService testScriptService) {
		this.testScriptService = testScriptService;
	}

	@Override
	@WebMethod
	@WebResult
	public CallResult configEnvironment() {
		return null;
	}

	@Override
	@WebMethod
	@WebResult
	public CallResult uploadTestScript(@WebParam TestScriptInfo testScriptInfo, @XmlMimeType("application/octet-stream") @WebParam DataHandler scriptData) {
		CallResult result = new CallResult();
		try {
			this.testScriptService.uploadTestScript(testScriptInfo, scriptData);
			result.setSuccess(true);
			result.setErrorMessage("");
		} catch (IOException ioException) {
			ioException.printStackTrace();
			result.setSuccess(false);
			result.setErrorMessage(ioException.getMessage());
		}
		return result;
	}

	@Override
	@WebMethod
	@WebResult
	public CallResult runTestCase(@WebParam RunConf runConf, @WebParam TestCaseInfo testCaseInfo, @WebParam String testCaseStr) {
		CallResult result = new CallResult();
		this.testScriptService.runTestCase(runConf, testCaseInfo, testCaseStr);
		result.setSuccess(true);
		result.setErrorMessage("");
		return result;
	}

	@Override
	@WebMethod
	@WebResult
	public StatusInfo getCurrentStatus() {
		return null;
	}

	@Override
	@WebMethod
	@WebResult
	public CallResult forcedRelease() {
		return null;
	}

	@Override
	@WebMethod
	@WebResult
	public CallResult cleanTestScript() {
		return null;
	}

	@Override
	@WebMethod
	@WebResult
	public CallResult cleanJunkFiles() {
		return null;
	}

}
